package org.mili.ticketeer.ui.meeting;

import org.mili.application.service.ServiceException;
import org.mili.application.service.ServiceFactory;
import org.mili.application.ui.SimpleTableModel;
import org.mili.ticketeer.dto.Meeting;
import org.mili.ticketeer.service.MeetingService;

import java.util.List;

/**
 */
public class MeetingTableModel extends SimpleTableModel<Meeting> {
    private static MeetingService meetingService = ServiceFactory.getService(MeetingService.class);

    public MeetingTableModel() {
        super(new String[]{"No.", "Date"});
        update();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Meeting meeting = get(rowIndex);
        switch(columnIndex) {
            case 0:
                return rowIndex + 1;
            case 1:
                return meeting.getDate();
            default: throw new IllegalStateException("no column index for: " + columnIndex);
        }
    }

    @Override
    public List<Meeting> load() {
        try {
            return meetingService.getMeetings();
        } catch (ServiceException e) {
            throw new IllegalStateException(e);
        }
    }

}
